<template>
  <div>
    <div class="lists">
      <div class="list">
        <em>课程名</em>
        <a
          href="javascript:;"
          v-for="items in listChooses.subjects"
          :key="items.id"
          @click="isshow(items, 1)"
          :class="{ show: items.id == index1 }"
        >
          {{ items.name }}
        </a>
      </div>
      <div class="list">
        <em>知识点</em>
        <a
          href="javascript:;"
          v-for="items in listChooses.labels[4].label"
          :key="items.sid"
          @click="isshow(items, 2)"
          :class="{ show: items.id == index2 }"
        >
          {{ items.name }}
        </a>
      </div>
      <div class="list">
        <em style="textindent: '1em'">难度</em>
        <a
          href="javascript:;"
          v-for="items in listChooses.diffc"
          :key="items.id"
          @click="isshow(items, 3)"
          :class="{ show: items.id == index3 }"
        >
          {{ items.name }}
        </a>
      </div>
    </div>
    <div class="show">
      <el-table ref="filterTable" :data="tableData" style="width: 100%">
        <el-table-column
          prop="question"
          label="题目"
          sortable
          column-key="date"
        >
        </el-table-column>
        <el-table-column prop="answer" label="题解" sortable column-key="date">
        </el-table-column>
        <el-table-column prop="pass" label="通过率" sortable column-key="date">
        </el-table-column>
        <el-table-column prop="difficult" label="难度" column-key="date">
        </el-table-column>
        <el-table-column prop="tag" label="标签" fixed="right">
          <template slot-scope="scope">
            <el-tag
              :type="scope.row.tag === '集合论' ? 'primary' : 'success'"
              disable-transitions
              >{{ scope.row.tag }}</el-tag
            >
          </template>
        </el-table-column>
        <el-table-column prop="whomake" label="出题人" column-key="date">
        </el-table-column>
        <el-table-column prop="subject" label="课程名" column-key="date">
        </el-table-column>
        <el-table-column label="收藏" fixed="right">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="success"
              round
              @click="handleCollect(scope.$index, scope.row)"
              >收藏</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script>
export default {
  name: "questionGroup",
  data() {
    return {
      index1: -1,
      index2: -1,
      index3: -1,
      name: ["", "", ""],
      listChooses: {
        subjects: [
          { id: 1, name: "离散数学" },
          { id: 2, name: "高等数学" },
          { id: 3, name: "计算机组成原理" },
          { id: 4, name: "C++高级程序设计" },
          { id: 5, name: "JAVA高级程序设计" },
        ],
        labels: [
          {
            sid: 1,
            label: [
              { id: 1, name: "图论" },
              { id: 2, name: "树" },
              { id: 3, name: "集合论" },
              { id: 4, name: "图论" },
            ],
          },
          {
            sid: 2,
            label: [
              { id: 1, name: "积分" },
              { id: 2, name: "不定积分" },
              { id: 3, name: "定积分" },
              { id: 4, name: "空间立体几何" },
            ],
          },
          {
            sid: 3,
            label: [
              { id: 1, name: "寄存器" },
              { id: 2, name: "加法器" },
              { id: 3, name: "编码" },
            ],
          },
          {
            sid: 4,
            label: [
              { id: 1, name: "类和对象" },
              { id: 2, name: "虚函数" },
              { id: 3, name: "模板" },
              { id: 4, name: "多态" },
              { id: 5, name: "容器" },
            ],
          },
          {
            sid: 5,
            label: [
              { id: 1, name: "类和对象" },
              { id: 2, name: "接口" },
              { id: 3, name: "继承" },
              { id: 4, name: "多线程" },
              { id: 5, name: "异常" },
              { id: 6, name: "集合论" },
              { id: 7, name: "内部类" },
              { id: 8, name: "图论" },
            ],
          },
        ],
        // diffc: ["入门", "简单", "中等", "较难", "困难"],
        diffc: [
          { id: 1, name: "入门" },
          { id: 2, name: "简单" },
          { id: 3, name: "中等" },
          { id: 4, name: "较难" },
          { id: 5, name: "困难" },
        ],
      },
      tableData: [
        {
          question: "1.两数之和",
          answer: "200",
          pass: "72.2%",
          difficult: "中等",
          subject: "离散数学",
          tag: "集何论",
          whomake: "张三",
        },
        {
          question: "5.最长回文子串",
          answer: "506",
          pass: "65.2%",
          difficult: "简单",
          subject: "离散数学",
          tag: "图论",
          whomake: "张学友",
        },
        {
          question: "10。正则表达式匹配",
          answer: "333",
          pass: "50.2%",
          difficult: "困难",
          subject: "高等数学",
          tag: "曲面积分",
          whomake: "蔡徐坤",
        },
        {
          question: "42.接雨水",
          answer: "958",
          pass: "60.2%",
          difficult: "中等",
          subject: "高等数学",
          tag: "集合论",
          whomake: "刘德华",
        },
      ],
      tableDatacp: [
        {
          question: "1.两数之和",
          answer: "200",
          pass: "72.2%",
          difficult: "中等",
          subject: "离散数学",
          tag: "集合论",
          whomake: "张三",
        },
        {
          question: "5.最长回文子串",
          answer: "506",
          pass: "65.2%",
          difficult: "简单",
          subject: "离散数学",
          tag: "图论",
          whomake: "张学友",
        },
        {
          question: "10。正则表达式匹配",
          answer: "333",
          pass: "50.2%",
          difficult: "困难",
          subject: "高等数学",
          tag: "曲面积分",
          whomake: "蔡徐坤",
        },
        {
          question: "42.接雨水",
          answer: "958",
          pass: "60.2%",
          difficult: "中等",
          subject: "高等数学",
          tag: "集合论",
          whomake: "刘德华",
        },
      ],
    };
  },
  methods: {
    isshow({ id, name }, x) {
      if (x == 1) {
        this.index1 = id;
        this.name[0] = name;
      } else if (x == 2) {
        this.index2 = id;
        this.name[1] = name;
      } else {
        this.index3 = id;
        this.name[2] = name;
      }
      this.tableData = this.tableDatacp.filter((el) => {
        if (this.name[0] != "" && this.name[1] != "" && this.name[2] != "")
          return (
            el.subject == this.name[0] &&
            el.tag == this.name[1] &&
            el.difficult == this.name[2]
          );
        else if (
          this.name[0] != "" &&
          this.name[1] == "" &&
          this.name[2] == ""
        ) {
          return el.subject == this.name[0];
        } else if (
          this.name[0] == "" &&
          this.name[1] !== "" &&
          this.name[2] == ""
        ) {
          return el.tag == this.name[1];
        } else if (
          this.name[0] == "" &&
          this.name[1] == "" &&
          this.name[2] != ""
        ) {
          return el.difficult == this.name[2];
        } else if (
          this.name[0] != "" &&
          this.name[1] != "" &&
          this.name[2] == ""
        ) {
          return el.subject == this.name[0] && el.tag == this.name[1];
        } else if (
          this.name[0] != "" &&
          this.name[1] == "" &&
          this.name[2] != ""
        ) {
          return el.subject == this.name[0] && el.difficult == this.name[2];
        } else if (
          this.name[0] == "" &&
          this.name[1] != "" &&
          this.name[2] != ""
        ) {
          return el.tag == this.name[1] && el.difficult == this.name[2];
        }
      });
    },
    handleCollect(a, b) {
      for (var i = 0; i < this.$store.state.quesCollect.questions.length; i++) {
        if (this.$store.state.quesCollect.questions[i].question == b.question) {
          this.$message({
            message: "不允许重复收藏",
            type: "warning",
            duration:1000,
            showClose:true
          });
          return;
        }
      }
      this.$store.state.quesCollect.questions.push(b);
      this.$message({
        message: "收藏成功，请在我的收藏中查看",
        type: "success",
        duration:1000,
        showClose:true
      });
    },
  },
};
</script>

<style scoped lang="less">
.show {
  color: deeppink !important;
  border-radius: 20px;
  border: 1px solid gray;
  background-color: rgb(217, 237, 255);
}
.lists {
  padding: 10px;
  width: 100%;
  background-color: rgb(200, 200, 255);
  border: 1px solid rgb(184, 193, 14);
  .list {
    height: 40px;
    line-height: 40px;
    em {
      font-weight: 700;
      padding: 20px;
    }
    a {
      text-decoration: none;
      text-align: center;
      color: black;
      padding-left: 10px;
      &:hover {
        color: deeppink;
      }
      border-left: 1px solid;
    }
  }
  &:hover {
    box-shadow: 1px 1px 5px 1px gray;
  }
}
.show {
  margin-top: 10px;
}
</style>